MAGIAPOTAGIA 1977: Translations by Jim Waterman
from the 16K Spectrum original by Daniel 'McFly' Aguilar
========================================================

In my review of Daniel "McFly" Aguilar's "Magiapotagia", which takes up just over 4K of the 48K Spectrum (the graphics won't work properly on the 16K model...), I speculated that it might be possible to write this piece of "magic" on a computer that was available when Joe Public would consider computers to be some kind of witchcraft, capable of what they perceived to be "magic".

It *is* possible, and I've managed it on all three of the "1977 Trinity", as they're collectively known. It takes compromises, as you'd expect, but the essence of Daniel's program is there in all of them. The cards are laid out in a similar way (for two out of the three versions, at least), I've kept the same text (if slightly corrected for SPG and positioning), and the results will be the same as on the Spectrum. Colour and sound are not a consideration on these early machines; the Apple II was capable of both, but not in the context of what we want here.

These versions also contain an extra tribute to the late, great, Paul Daniels. You'll like it - not a lot, but you'll like it.

For the modern translations of the sale prices of the computers in the US in 1977, all inflation and exchange rates were calculated on 26 November 2021.



APPLE II (INTEGER BASIC) VERSION
magiapotagia1977.aws.yaml - 25 November 2021
--------------------------------------------

The Apple II was released in June 1977, with its base model listed for sale to American buyers at $1,298 - the equivalent of $5,924 today, or £4,442 in our money, and €5,236 on the continent. The highest-spec 48K model was roughly twice that amount - but early adopters of new technology will pay through the nose for it, and there are always some who must have it. So, for those with very deep pockets 44 years ago, it was possible to buy a computer, and program it to scare the neighbours into thinking robots were about to take over the world and make the puny humans into slaves...

After a quick overview of the capabilities of the BASIC that was available from launch on the "1977 Trinity", the Apple II looked the most qualified for the job I wanted. It took a day of reading the manual, bashing the Spectrum listing into something that the Apple II would actually accept with correct syntax, and then the rest of the day grappling with the Integer BASIC's idiosyncrasies - such as the way it handles and concatenates strings, how there can only be one statement that's actually executed after THEN in an IF... THEN line, the bizarre method of clearing the screen with a direct call to ROM, and that it can't PRINT the underline character - there isn't a key for it on the original computer's keyboard, there's no CHR$ function and even on an emulator, PRINT "_" gives a syntax error.

But I made it, and then fell at the final hurdle for what I stipulated for the 2021 CSSCGC: final submissions should not be snapshots. The original Apple II only had access to a cassette recorder, and AppleWin 1.30.6.0 only has provisions for disc drives - it does not emulate the cassette at all (SAVE and LOAD will do what they're supposed to do but no .TAP or .CAS file or anything else is ever created). So a snapshot with the bizarre double-extension .AWS.YAML is what you get. Load it into AppleWin, preferably version 1.30.60.0 whch I used, and RUN the program. I had to get rid of error checks for the "L/M/R?" input as everything I tried caused inexplicable errors. Just stick to what you're told and everything will work - as it would have done in 1977.

AppleWin 1.30.60.0 emulator:
https://github.com/AppleWin/AppleWin/releases/tag/v1.30.6.0
Apple II Integer BASIC programming manual:
https://archive.org/details/apple-ii-basic-programming/mode/2up

TO LOAD THIS VERSION:
- Start AppleWin, press F12 and navigate to where the snapshot is stored.
- Select it, then select "Open"... and you're there. Type RUN and ENTER.

Also, there's no need to do this when using the snapshot, but after resetting the Apple II you'll see a screen full of ? and inverse @ characters and a * prompt. You'll need to press CTRL+B then ENTER to get to BASIC, where the prompt will change to > instead. It took a while to find that out. From this point, if there was a way to load a tape image, the command is LOAD with no filename.



COMMODORE PET (BASIC 1.0) VERSION
magiapotagia1977.tap - 26 November 2021
---------------------------------------

The Apple II was only for people with very deep pockets in 1977. The Commodore PET, in its huge pyramid-like case, was available to its American customers from December 1977 for the low, low price of just $795 - not that low, actually, it's still $3,628 in today's money, that's £2,721 or €3,207 on the other side of the Atlantic.

The PET was the second version of this program that I tackled, using the original 2001-8N model that Christmas shoppers in 1977 would have bought. Any trepidation I might have had that Commodore BASIC is a long string of POKEs and weird control characters ("my listing is full of hearts, Qs and brackets!") was tempered because I'm already aware that the Commodore 64 uses an updated version of the same BASIC, and a program from one can be loaded into the other if there are no conflicts. I've done a Spectrum conversion of an educational Computer Haiku program from 1983:
https://archive.org/details/Computer_Haiku_1983_CES
Lots and lots of POKEs and SYS calls are installed, to ensure that the all-singing-all-dancing and (not very brightly) coloured C64 version can modify itself to run on the PET.

I used the Apple II listing as the starting point, seeing as it was heavily compacted from the Spectrum original, but retained the Spectrum's use of arrays to move the cards around - even the rudimentary PET BASIC 1.0 has string arrays, and (as is usually standard) doesn't need the extra dimension that the Spectrum does. So it was relatively straightforward - even the weird array of control characters soon made sense, and the PET even had some bonus line graphics on its shifted keys. Unfortunately, half the graphics I needed weren't available from the keyboard (not that I could find, anyway) but not to worry, PET BASIC 1.0 has the CHR$ function that Apple II Integer BASIC lacks. I'd even managed to work out a way to clear a part of the screen using a string variable filled with delete-left control character CHR$(20), but because it moves the cursor backwards, it wa a lot easier to clear the screen upwards. Call that a quirk of this machine.

Everything seemed to be going well, but some quirks of VICE 3.3 intervened. For a start, snapshots caused the keyboard to change to a Japanese layout, with the effect that QWERTY appeared as SDFGHJK and any attempt to change it reset the computer; on any model other than the PET 2001-8N, it would crash outright. Not to worry, though, there's the Datasette, isn't there? But no matter what I tried, when I saved the final version to tape (the original PET wasn't equipped with a disc drive so I wasn't going to allow a disc version of the final program), the reloaded tape would never RUN and would only LIST once, after loading. 

On trying to load the tape into a C64, seeing as I knew it was possible, the listing appeared intact, just with the initial REM statement corrupted into a line "10794" that wasn't there and couldn't be removed by any means that I knew. But the program was definitely there, and after half a day's worth of investigations, I found that if I tried to load it into the PET 3008, the 2001-8N's 1979 successor with BASIC 2.0, it loaded and ran fine.

So that is the version I will stick with. I have provided the listing, so it you want proof that this *will* run on a 1977 PET 2001-8N, treat it as a type-in. If you want to see it running, switch VICE to the PET 3008. You can even trim the memory down to 4 KB and see it run in the smallest available memory.

VICE emulator (for C64, C128, VIC-20, PET, and Minus/60):
https://vice-emu.sourceforge.io
Using version 3.3 for 32-bit Windows:
http://sourceforge.net/projects/vice-emu/files/releases/binaries/windows/GTK3VICE-3.3-win32.7z/download
PET BASIC programming manual:
http://www.zimmers.net/anonftp/pub/cbm/manuals/pet/An%20introduction%20to%20your%20new%20PET%20(original).pdf

TO LOAD THIS VERSION: 
- Start the emulation with XPET.EXE.
- Select Settings > Settings (no, that's not a typo) and the following options:
	= Machine > Model settings > PET 3008 and keep everything else as it chooses;
	= I/O extensions > Tape port devices and make sure "Enable Datasette" has a tick it - it may not do by default! Change "Tape wobble" to 0.
- Select File > Attach tape image, and navigate to magiapotagia1977.tap.
- Type LOAD"MAGIA77",1,1 and ENTER (actually only LOAD is needed, but this is the full Commodore BASIC syntax).
- Left-click on "Tape:000" at the bottom right and select Start. (Right-click will show the contents of the tape.)



TRS-80 MODEL I (LEVEL I BASIC) VERSION
magiapotagia1977.cas - 26 November 2021
---------------------------------------

The Tandy/Radio Shack TRS-80 was the bargain-basement computer of 1977. It was the second of the "Trinity" to be launched, in August of that year. And if the horrific cost of the Apple II put the average American customer right off the idea of a computer, it would only require parting with a  Wal-mart-esque $399 (albeit from your local branch of Radio Shack) to own a TRS-80. That's $1,281 today, about the price of a laptop with a 15.6" screen, top-notch Intel i7 processor, 16 GB RAM and 1 TB SSD - not bad. (I checked at Best Buy's US website.) Over here, that's the equivalent of £960 - into three digits! - or €1,132 over the Channel.

But of the three, the "Trash-80" was the cheap option, and *it showed*.

Every BASIC has its limitations, especially those from the early days. The TRS-80 had floating point arithmetic, which the initial Apple II (at more than three times the cost) didn't - but that's not a lot of use to me here. For my purposes, it is extremely deficient in its ability to handle strings. You get two string variables - A$ and B$ - limited to 16 characters each. You get 26 numerical variables A-Z, and one numerical array A(255), which appears to be permanently populated.

Such limitations were not going to put me off, as there was enough space to simulate the arrays L$, M$, R$ and B$ in the numerical array A - one character per element, 84 required, plenty left over. Storing the array 1A, 2A, 3A etc. as their ASCII characters was no good, though - Level I BASIC has no CHR$ function and couldn't do that translation. In the end it was just a case of storing the values as 1-9 and 10-14 for A, B, J, X and Z, and throwing a load of IF...THENs at it in a subroutine. Two string variables - who needs them? I didn't use either of them - it's all been achieved numerically.

Level I BASIC has the rudimentary low-resolution graphics I'm familiar with from experimenting with my brother's Dragon 32 back in the day, SET and RESET, though in a grid more like the BBC Micro with 2×3 blocks per character square. At least it was possible to use them in conjunction with text, unlike the Apple II. So I used the graphics, at the expense of speed - it really is *very slow* as there is no DRAW command or similar, just a series of SETs (a bit like on the ZX81). Fortunately, if you hold down F12, the emulation will run at 4× normal speed.

Also, due to the rectangular pixels of the TRS-80, the screen layout is completely different to all the other versions - 64 columns but only 16 rows, so the text is beside the cards. And I had to be very careful with placing the text so that it didn't blank out large chunks of the screen.

TRS-80GP is an excellent emulator that offers a huge range of models in the TRS-80 range, and can be customised on the command line. I've provided TRS80.BAT - drop it into the same folder as TRS80GP.EXE to start the emulation of a Model I with the original ROM, Level I BASIC, the correct sized window and the minimum 4 KB of RAM. It's the poverty-spec computer of 1977 and it still managed to do the job. Add the filename of a .BAS file onto the command line and it will load automatically - meaning I could edit the program in Notepad++ and load it quickly and easily, which was excellent as it was the hardest to get a result from!

The files provided are:
- magiapotagia1977.cas: the standard tape image, made from the "compact" version of the BASIC listing.
- magiapotagia1977_full.bas (2,520 bytes): the listing typed out in full with spacing to make it legible, and some extra annotating REMs. This is the equivalent of the text listings given with the Apple II and PET versions.
- magiapotagia1977_compact.bas (2,203 bytes): the same listing, with all the spaces removed except in PRINT statements, fewer REMs, and unnecessary GOTOs removed. It's hard to read but the computer will still RUN it fine.
- magiapotagia1977_short.bas (2,019 bytes): the compact listing further compressed with Level I BASIC's shorthand ("P." for PRINT, "F." for FOR, etc.) as in the programming manual. It's even harder to understand than the compact listing, but see it as the TRS-80's equivalent of a 1K ZX81 listing full of NOT PIs and VALs to same precious memory.

TRS-80GP emulator v2.4.4:
http://48k.ca/trs80gp.html
TRS-80 Model I documentation:
http://www.akhara.com/trs-80/docs/model1/
TRS-80 Level I Users Manual:
http://www.akhara.com/trs-80/docs/model1/Level%201%20Users%20Manual%20(1977)(David%20Lien)(pdf).zip

TO LOAD THIS VERSION: 
- Start the emulation with TRS80.BAT.
- Select Cassette > Insert > magiapotagia1977.cas and Open.
- Type CLOAD and ENTER, and wait for it.
